package calcs;

import gui.MyFrame;
import gui.data.D2.PointsIn2DOutputGui;
import static util.Util.*;

public class XYDistanceCalculator extends Thread{
	double x1, x2, y1, y2, distance, dx, dy;
	String vector = "";
	MyFrame myFrame = null;

	public XYDistanceCalculator(double x1, double y1, double x2, double y2, MyFrame myFrame) {
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
		this.myFrame = myFrame;
		start();
	}
	
	public XYDistanceCalculator(double x1, double y1, double x2, double y2) {
		this.x1 = x1;
		this.x2 = x2;
		this.y1 = y1;
		this.y2 = y2;
	}

	public void run() {
		dx = roundToDecimals(x2 - x1, 3);
		dy = roundToDecimals(y2 - y1, 3);
		vector = "( " + dx + " ; " + dy + " )";
		distance = roundToDecimals(Math.sqrt((Math.pow(dx, 2) + Math.pow(dy, 2))), 3);
		if(myFrame != null){
			myFrame.setDataPanel(new PointsIn2DOutputGui(x1,y1,x2,y2,distance,vector), "XYDISTANCE_OUTPUT");
		}
	}
}
